package cn.cheegon.blog.controller;

import cn.cheegon.blog.common.api.CommonPage;
import cn.cheegon.blog.common.api.CommonResult;
import cn.cheegon.blog.entity.dto.*;
import cn.cheegon.blog.entity.rsp.BlogListRsp;
import cn.cheegon.blog.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Desc:
 * @Author: cheegon
 * @Date: Create in 2024/6/12  下午5:49
 */
@Tag(name = "游客api")
@Slf4j
@RestController
@RequestMapping("/tourist/*")
public class TouristController {

    @Autowired
    private PmsTypeService pmsTypeService;

    @Autowired
    private PmsTagService pmsTagService;

    @Autowired
    private CmsBlogService cmsBlogService;

    @Autowired
    private PmsProjectService pmsProjectService;

    @Autowired
    private CmsMessageService cmsMessageService;

    @Autowired
    private CmsCommentService cmsCommentService;

    @Autowired
    private CmsEssayService cmsEssayService;

    @GetMapping("/type/{id}")
    public CommonResult<PmsTypeDto> getTypeById(@PathVariable Long id) {
        return CommonResult.success(pmsTypeService.getItemById(id));
    }

    @Operation(summary = "获取类型里列表", description = "")
    @GetMapping("getTypeList")
    public CommonResult<CommonPage<PmsTypeDto>> getTypeList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        CommonPage<PmsTypeDto> list = pmsTypeService.getList(pageNum, pageSize);
        return CommonResult.success(list);
    }

    @GetMapping("getTopTypeList")
    public CommonResult<List<PmsTypeDto>> getTopTypeList(@RequestParam(name = "size", defaultValue = "6") Integer size) {
        List<PmsTypeDto> list = pmsTypeService.getTopList(size);
        return CommonResult.success(list);
    }

    @GetMapping("getAllTypeList")
    public CommonResult<List<PmsTypeDto>> getAllTypeList() {
        return CommonResult.success(pmsTypeService.getAllList());
    }

    @GetMapping("tag/{id}")
    public CommonResult<PmsTagDto> getTagById(@PathVariable Long id) {
        return CommonResult.success(pmsTagService.getItem(id));
    }

    @GetMapping("getTagList")
    public CommonResult<CommonPage<PmsTagDto>> getTagList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                          @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        return CommonResult.success(pmsTagService.getList(pageNum, pageSize));
    }

    @GetMapping("getTopTagList")
    public CommonResult<List<PmsTagDto>> getTopTagList(@RequestParam(name = "size", defaultValue = "10") Integer size) {
        return CommonResult.success(pmsTagService.getTopList(size));
    }

    @GetMapping("getAllTagList")
    public CommonResult<List<PmsTagDto>> getAllTagList() {
        return CommonResult.success(pmsTagService.getAllList());
    }

    @GetMapping("getBlogList")
    public CommonResult<CommonPage<BlogListRsp>> getBlogList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
                                                            @RequestParam(value = "kwd", required = false) String kwd,
                                                            @RequestParam(value = "tagId", required = false) Long tagId,
                                                            @RequestParam(value = "typeId", required = false) Long typeId) {
        return CommonResult.success(cmsBlogService.getList(kwd, tagId, typeId, pageNum, pageSize));
    }

    @GetMapping("getRecommendBlogList")
    public CommonResult<List<BlogListRsp>> getRecommendBlogList(@RequestParam(name = "size", defaultValue = "6") Integer size) {
        return CommonResult.success(cmsBlogService.getRecommendList(size));
    }

    @GetMapping("blog/{id}")
    public CommonResult<CmsBlogDto> getBlogById(@PathVariable Long id) {
        return CommonResult.success(cmsBlogService.getItem(id));
    }

    @GetMapping("reportView/{id}")
    public CommonResult getReportView(@PathVariable Long id) {
        cmsBlogService.getReportView(id);
        return CommonResult.success();
    }

    @GetMapping("messageList")
    public CommonResult<CommonPage<MessageDto>> getMessageList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        return CommonResult.success(cmsMessageService.getList(pageNum, pageSize));
    }

    @GetMapping("essayList")
    public CommonResult<CommonPage<EssayDto>> getEssayList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                           @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        return CommonResult.success(cmsEssayService.getList(null, pageNum, pageSize));
    }

    @GetMapping("commentList")
    public CommonResult<CommonPage<CommentTreeDto>> getCommentList(@RequestParam(name = "blogId") Long blogId,
                                                               @RequestParam(name = "parentId", defaultValue = "0") Long parentId,
                                                               @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        return CommonResult.success(cmsCommentService.getTreeList(blogId,  parentId, pageNum, pageSize));
    }
    @GetMapping("childCommentList")
    public CommonResult<List<CommentTreeDto>> getChildCommentList(@RequestParam(name = "blogId") Long blogId,
                                                               @RequestParam(name = "parentId", defaultValue = "0") Long parentId,
                                                                  @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        return CommonResult.success(cmsCommentService.getChildCommentList( blogId, parentId, pageNum, pageSize));
    }

    @GetMapping("projectList")
    public CommonResult<CommonPage<ProjectDto>> getProjectList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        return CommonResult.success(pmsProjectService.getList(null, pageNum, pageSize));
    }
}
